﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class ExpoInfoProvider : BaseProvider<ExpoInfoProvider.RequestDataInfo>, IDataProvider
    {
        public ExpoInfoProvider(string _jsonInfo): base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            IMessageInfo message = new MessageInfo();
            message.code = (int)MessageCodeType.Success;
            message.message = Utils.GetEnumDescription(MessageCodeType.Success);
            message.data = ProcessResponseData();

            return message;
            
        }

        private ResponseDataInfo ProcessResponseData()
        {
            //use postdata.data to process responseData
            ResponseDataInfo resData = new ResponseDataInfo();

            TbExpoManager expomanager = new TbExpoManager();

            TbExpoEntity expoEntity = expomanager.GetModelByCache(Constants.EXPO_ID);
            if (expoEntity == null)
                return resData;

            /*
             {
                "code":0,
                "message":"OK",
                "data":
                 {"logo":"图片url",
                  "name":"展会名称",
                  "date":"展会日期,文本",
                  "address":"上海展览馆",
                  "website":"http://www.chinaclean.com",
                  "summary":"简介"
                 } 
            }
             */


            resData.logo = ConfigHelper.GetConfigString("WebsiteImageUrl") + expoEntity.logo;
            resData.name = expoEntity.expoName;

            if (expoEntity.beginDate.ToString("yyyy-M-d") == expoEntity.endDate.ToString("yyyy-M-d"))
            {
                resData.date = expoEntity.beginDate.ToString("yyyy年M月d日");
            }
            else
                resData.date = expoEntity.beginDate.ToString("yyyy年M月d日") + "--" + expoEntity.endDate.ToString("d日");

            resData.address = expoEntity.address;
            resData.website = expoEntity.website;
            resData.summary = expoEntity.summary;

            return resData;
        }

        public class RequestDataInfo 
        {
            public string name { get; set; }
            public DateTime date { get; set; }
        }

        public class ResponseDataInfo
        {
            public string logo { get; set; }
            public string name { get; set; }
            //DateTime类型统一以文本返回
            public string date { get; set; }
            public string address { get; set; }
            public string website { get; set; }
            public string summary { get; set; }

        }


    }
}
